package controller.subsystemcom;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import controller.acquaintance.I_Vision;
import controller.acquaintance.I_WorkCellController_Vision;
import controller.model.WorkCellControllerServer;

public class VisionSystem implements I_Vision
{
	private static VisionSystem instance;
	private I_WorkCellController_Vision workCellController;
	
	private VisionSystem()
	{
		try
		{
			workCellController = (I_WorkCellController_Vision) Naming.lookup(WorkCellControllerServer.rmiVision);
		}
		catch (MalformedURLException e)
		{ e.printStackTrace(); }
		catch (RemoteException e)
		{ e.printStackTrace(); }
		catch (NotBoundException e)
		{ e.printStackTrace(); }
	}
	
	public static VisionSystem getInstance()
	{
		if (instance == null)
			instance = new VisionSystem();
		return instance;
	}
	
	public void newYellowBrickSpotted(double x, double y, double angle, long time)
	{
		try
		{
			//x and y are switched due to the robot controller
			workCellController.newYellowBrickSpotted(y, x, angle, System.currentTimeMillis());
		}
		catch (RemoteException e)
		{ e.printStackTrace(); }
	}
	
	public void newRedBrickSpotted(double x, double y, double angle, long time)
	{
		try
		{
			//x and y are switched due to the robot controller
			workCellController.newRedBrickSpotted(y, x, angle, System.currentTimeMillis());
		}
		catch (RemoteException e)
		{ e.printStackTrace(); }
	}
	
	public void newBlueBrickSpotted(double x, double y, double angle, long time)
	{
		try
		{
			//x and y are switched due to the robot controller
			workCellController.newBlueBrickSpotted(y, x, angle, System.currentTimeMillis());
		}
		catch (RemoteException e)
		{ e.printStackTrace(); }
	}
}
